$().ready(function () {
    validateRule();
    $(document).ready(function () {//通用方法去输入框去除空格
        $("form").on("change", function () {
            $("form input[type=text]").each(function () {
                this.value = this.value.replace(/\s+/g, '');
            });
        })
    });
    var channeltype = $('#sdktypehidden').val();
    $('#sdktype').val(channeltype);
});

$.validator.setDefaults({
    submitHandler: function () {
        update();
    }
});

function update() {

    $.ajax({
        url: "/market/sdk/sdkJudgingUniqueEdit",
        type: "post",
        data: $('#signupForm').serialize(),
        success: function (r) {
            if (r.code == 0) {
                $.ajax({
                    cache: true,
                    type: "POST",
                    url: "/market/sdk/update",
                    data: $('#signupForm').serialize(),// 你的formid
                    async: false,
                    error: function (request) {
                        parent.layer.alert("Connection error");
                    },
                    success: function (data) {
                        if (data.code == 0) {
                            parent.layer.msg("操作成功");
                            parent.reLoad();
                            var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                            parent.layer.close(index);

                        } else {
                            parent.layer.alert(data.msg)
                        }

                    }
                });
            } else {
                layer.alert("SDK名称重复或版本号重复!");
            }
        }
    });
}

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm").validate({
        rules: {
            sdkname: {
                required: true
            }
            ,
            sdkver: {
                required: true
            }
        }
        ,
        messages: {
            sdkname: {
                required: icon + "请输入SDK名称"
            }
            ,
            sdkver: {
                required: icon + "请输入SDK版本号"
            }
        }
    })
}